package com.ssm.studen.controller;

import com.ssm.studen.model.Loginlog;
import com.ssm.studen.service.LoginlogService;
import com.ssm.studen.tool.ResponseMessage;
import com.ssm.studen.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 登录日志表：
 *          对外提供数据服务接口
 */
@Api(tags = "loginlog")
@RestController
public class LoginlogController {

    @Autowired
    private LoginlogService loginlogService;


    /********************登录日志查询**********************/
    @ApiOperation("登录日志通过主键查询")
    @RequestMapping(value = "/selectLoginlog",method = RequestMethod.PUT)
    public ResponseMessage selectLoginlog(int lnum){
        Map<String,List> map = new HashMap<>();
        List<Loginlog> listLogin = loginlogService.selectLoginlog(lnum);
        map.put("list",listLogin);
        return Result.success("200",map);
    }


    /********************登录日志添加**********************/
    @ApiOperation("登录日志添加")
    @RequestMapping(value = "/insertLoginlog",method = RequestMethod.GET)
    public int insertLoginlog(Loginlog loginlog){
        int IsAdd = 0;
        //传入数据判断
        //1.实体对象不能为空
        if(loginlog != null){
            //2.不能为空
            if(loginlog.getLnum()!=0&&
                    loginlog.getLtime()!=null&&
                    loginlog.getLlocation()!=null&&
                    loginlog.getPnum()!=0){
                //3.添加数据
                IsAdd = loginlogService.insertLoginlog(loginlog);
            }
        }
        return IsAdd;
    }
}
